package com.junit;

import org.apache.commons.codec.binary.Base64;
import org.junit.Test;

import com.xpgk.mvc.user.User;
import com.xpgk.tools.ToolRandoms;
import com.xpgk.tools.security.ToolIDEA;
import com.xpgk.tools.security.ToolPbkdf2;

public class TestUser extends TestBase {

	@Test
	public void addUser() {
		try {
			User user = new User();
			String ids = ToolRandoms.getUuid(true);
			// 密码加密
			byte[] salt = ToolPbkdf2.generateSalt();// 密码盐
			byte[] encryptedPassword = ToolPbkdf2.getEncryptedPassword("123456", salt);
			user.set("username", "xpgk");
			user.set(User.column_salt, Base64.encodeBase64String(salt));
			user.set(User.column_password, Base64.encodeBase64String(encryptedPassword));

			// 初始化idea密钥
			String secretKey = Base64.encodeBase64String(ToolIDEA.initKey());
			user.set(User.column_secretkey, secretKey);

			// 保存用户
			// user.set(User.column_errorcount, 0);
			user.set(User.column_status, "1");
			user.save(ids);
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

}
